package com.ian;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableDiscoveryClient
@SpringBootApplication
@EnableFeignClients
@MapperScan("com.ian.dao")
@EnableSwagger2
public class IanApplication {
    public static void main(String[] args) {
        SpringApplication.run(IanApplication.class, args);
    }

    /*
    在SpringBoot工程中注册一个Servlet
 */
    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        HystrixMetricsStreamServlet hystrixMetricsStreamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(hystrixMetricsStreamServlet);
        //自定义Servlet请求路径
        servletRegistrationBean.addUrlMappings("/hystrix.stream");
        //自定义Servlet名称
        servletRegistrationBean.setName("HystrixMetricsStreamServlet");
        //定义该Servlet的启动参数
        servletRegistrationBean.setLoadOnStartup(1);
        return servletRegistrationBean;
    }
}
